#include "myshape.h"
#include <Graphic3d_Group.hxx>
#include <Prs3d_Root.hxx>
#include <Graphic3d_AspectLine3d.hxx>
#include <Graphic3d_ArrayOfTriangles.hxx>
#include <Graphic3d_ArrayOfPolylines.hxx>
#include <Graphic3d_Array1OfVertex.hxx>


IMPLEMENT_STANDARD_HANDLE(MyShape, AIS_InteractiveObject)
IMPLEMENT_STANDARD_RTTIEXT(MyShape, AIS_InteractiveObject)
MyShape::MyShape()
{
}

void MyShape::make_triangles(Handle(Graphic3d_Group) theGroup)
{
    Standard_Integer aNbTria = 2;
    Handle(Graphic3d_ArrayOfTriangles) aTriangles = \
            new Graphic3d_ArrayOfTriangles(3 * aNbTria, 0, Standard_True);
    Standard_Integer anIndex;
    for(anIndex = 1; anIndex <= aNbTria; aNbTria++)
    {
        aTriangles->AddVertex(anIndex * 5.0, 0.0, 0.0, 1.0, 1.0, 1.0);
        aTriangles->AddVertex(anIndex * 5.0 + 5.0, 0.0, 0.0, 1.0, 1.0, 1.0);
        aTriangles->AddVertex(anIndex * 5.0 + 2.5, 5.0, 0.0, 1.0, 1.0, 1.0);
    }

    theGroup->AddPrimitiveArray(aTriangles);
}

void MyShape::make_polyline(Handle_Graphic3d_Group theGroup)
{
    Standard_Real Xm, Ym, Zm, XM, YM, ZM;

    theGroup->Structure()->MinMaxValues(Xm, Ym, Zm, XM, YM, ZM);

    Handle(Graphic3d_ArrayOfPolylines) aPolylines = \
            new Graphic3d_ArrayOfPolylines(16, 4);
    aPolylines->AddBound(4);

}

void MyShape::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,\
                          const Handle(Prs3d_Presentation)& aPresentation,\
                          const Standard_Integer aMode)
{
    Handle(Graphic3d_Group) theGroup = Prs3d_Root::CurrentGroup(aPresentation);
    Quantity_Color Blue(Quantity_NOC_MATRABLUE);
    Handle(Graphic3d_AspectLine3d) CTXLBLUE = new Graphic3d_AspectLine3d();
    theGroup->SetPrimitivesAspect(CTXLBLUE);

    make_triangles(theGroup);

    static char *text[3] = {"Application title",
                            "My company",
                            "My company address"};

    Graphic3d_Array1OfVertex Tpts8(0, 1);
    Tpts8(0).SetCoord(-40.0, -40.0, -40.0);
    Tpts8(1).SetCoord(40.0, 40.0, 40.0);
    //theGroup->M
    Graphic3d_Vertex Marker(0.0, 0.0, 0.0);

    for(int i=0; i<=2; i++)
    {
        Marker.SetCoord(-(Standard_Real)i*4+30,\
                        (Standard_Real)i*4,
                        -(Standard_Real)i*4);
        theGroup->Text(text[i], Marker, 20.0);
    }
}

void MyShape::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,\
                                   const Standard_Integer aMode)
{

}

//void MyShape::Compute(const Handle(Prs3d_Projector)& aProjector,\
//                          const Handle(Prs3d_Presentation)& aPresentation)
//{

//}
